package com.oceansoft.mobile.common.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.codec.binary.Base64;

public final class Base64Utils {
	
	public static String getBase64(File file){
		InputStream in = null;
		byte[] data = null;
		// 读取图片字节数组
		try {
			in = new FileInputStream(file);
			data = new byte[in.available()];
			in.read(data);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	   return new String(Base64.encodeBase64(data));
	}
	
	public static String getBase64(InputStream in){
		 
		byte[] data = null;
		// 读取图片字节数组
		try {
			data = new byte[in.available()];
			in.read(data);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	   return new String(Base64.encodeBase64(data));
	}
	
	
	public static String getBase64(byte[] data){
		 return new String(Base64.encodeBase64(data));
	}
	
	
}
